home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / penguin.swf / scripts / __Packages / ExtMath.as next >
Encoding:
Text File  |  2007-06-26  |  1.9 KB  |  83 lines

  1. class ExtMath extends Math
  2. {
  3.    static var __proto__ = Math;
  4.    function ExtMath()
  5.    {
  6.       super();
  7.    }
  8.    static function distance(x1, y1, x2, y2)
  9.    {
  10.       var _loc1_ = x2 - x1;
  11.       var _loc2_ = y2 - y1;
  12.       return Math.sqrt(_loc1_ * _loc1_ + _loc2_ * _loc2_);
  13.    }
  14.    static function distance2(x1, y1, x2, y2)
  15.    {
  16.       var _loc1_ = x2 - x1;
  17.       var _loc2_ = y2 - y1;
  18.       return _loc1_ * _loc1_ + _loc2_ * _loc2_;
  19.    }
  20.    static function degreesToRadians(angle)
  21.    {
  22.       return angle * 0.01745329;
  23.    }
  24.    static function radiansToDegrees(angle)
  25.    {
  26.       return angle * 57.29578;
  27.    }
  28.    static function sinD(angle)
  29.    {
  30.       return Math.sin(angle * 3.141593 / 180);
  31.    }
  32.    static function asinD(ratio)
  33.    {
  34.       return Math.asin(ratio) * 57.29578;
  35.    }
  36.    static function cosD(angle)
  37.    {
  38.       return Math.cos(angle * 3.141593 / 180);
  39.    }
  40.    static function acosD(ratio)
  41.    {
  42.       return Math.acos(ratio) * 57.29578;
  43.    }
  44.    static function tanD(angle)
  45.    {
  46.       return Math.tan(angle * 3.141593 / 180);
  47.    }
  48.    static function atan2D(y, x)
  49.    {
  50.       return Math.atan2(y,x) * 57.29578;
  51.    }
  52.    static function angleOfLine(x1, y1, x2, y2)
  53.    {
  54.       return ExtMath.atan2D(y2 - y1,x2 - x1);
  55.    }
  56.    static function fixAngle(angle)
  57.    {
  58.       angle %= 360;
  59.       return angle % 360 >= 0 ? angle : angle + 360;
  60.    }
  61.    static function cartesianToFlash(o)
  62.    {
  63.       o._y *= -1;
  64.       o._rotation *= -1;
  65.    }
  66.    static function flashToCartesian(o)
  67.    {
  68.       return ExtMath.cartesianToFlash(o);
  69.    }
  70.    static function cartesianToPolar(p)
  71.    {
  72.       var _loc2_ = Math.sqrt(p.x * p.x + p.y * p.y);
  73.       var _loc3_ = ExtMath.atan2D(p.y,p.x);
  74.       return {r:_loc2_,t:_loc3_};
  75.    }
  76.    static function polarToCartesian(p)
  77.    {
  78.       var _loc2_ = p.r * ExtMath.cosD(p.t);
  79.       var _loc3_ = p.r * ExtMath.sinD(p.t);
  80.       return {x:_loc2_,y:_loc3_};
  81.    }
  82. }
  83.